import {
	defineStore
} from 'pinia'
	

const usePriceStore = defineStore('price', () => {
	const coin = ref(uni.getStorageSync('coin') || 'zh');
	const rate = ref(1)
	
	async function getrate(){
		await uni.$post({
			url:'/api/center/getHotlineuration',
			data:{
				type:3
			}
		}).then(res=>{
			rate.value = res.data;
		})
	}
	
	const getprice = price=>{
		// en zh 暂定 1$=6.5￥
		if(coin.value=='zh'){
			// return link;
			return '￥'+(Number(price).toFixed(0))
		}else{
			return '$'+((price / rate.value).toFixed(0))
		}
	};
	
	const up = ()=>{
		if(coin.value=='zh'){
			coin.value='en'
		}else{
			coin.value='zh'
		}
		uni.setStorageSync('coin',coin.value)
	}
	
	return {
		getrate,
		getprice,
		up
	}
})
export default usePriceStore;